//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口.未解决;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class demo_2653 {
    public demo_2653() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{1, -1, -3, -2, 3};
        System.out.println(getSubarrayBeauty(nums, 3, 2));
    }

    public static int[] getSubarrayBeauty(int[] nums, int k, int x) {
        int n = nums.length;
        int[] res = new int[n - k + 1];
        List<Integer> list = new ArrayList();

        for(int i = 0; i < n; ++i) {
            int in = nums[i];
            int index = Collections.binarySearch(list, in);
            index = index < 0 ? -index - 1 : index;
            list.add(index, in);
            if (i >= k - 1) {
                int num = (Integer)list.get(x - 1);
                int out = i - (k - 1);
                res[out] = Math.min(num, 0);
                list.remove(nums[out]);
            }
        }

        return res;
    }
}
